home *** CD-ROM | disk | FTP | other *** search
- Path: telepost.no!usenet
- From: Carsten Arnholm <ca@sesam.dnv.no>
- Newsgroups: comp.lang.c++
- Subject: For Experts: How to load a DLL dynamically ?
- Date: 15 Mar 1996 13:23:22 GMT
- Organization: DNV
- Message-ID: <4ibr0a$8f9@nms.telepost.no>
- NNTP-Posting-Host: hugin.sesam.dnv.no
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1 (Windows; I; 32bit)
-
- Hi everyone,
-
- I have a problem which I'm sure some of you experts can solve (???):
- I'm using MSVC++ 4.0 under Windows NT 3.51.
-
- I am unable to load a DLL exporting classes. If the DLL only exports
- simple API functions, I can do:
-
- // load the library
- HINSTANCE myDLL = LoadLibrary("myDLL.dll");
- const FARPROC myDLLfunc = GetProcAddress(myDLL ,"myDLLfunc");
-
- // call a function in the DLL that returns an int
- int value = myDLLfunc();
-
- // DLL no longer needed
- FreeLibrary(myDLL);
-
- This is straightforward ...
-
-
- But what do I do if I have a DLL which export classes ? i.e.
-
- #ifdef DLL_IMPLEMENTATION
- #define IMPORT_EXPORT _declspec(dllexport)
- #else
- #define IMPORT_EXPORT _declspec(dllimport)
- #endif
-
- class IMPORT_EXPORT DLLfoo { // class exported from dll
- public:
- DLLfoo(); // constructor
- int bar(); // some member function
- private:
- int value;
- };
-
- In an application using the DLL, I want to:
-
- DLLfoo foo; // create object from DLL class DLLfoo
- int somevalue = foo.bar(); // call member function of that class
-
- This is no problem if I link the application using the import library
- of my DLL, but that means that the DLL is "started" together with the
- application, whether I need it or not.
-
- If I don't link with the import library, there are lots of unresolved
- symbols (of course), and I can't figure out how to do something
- similar to LoadLibrary/GetProcAddress for my classes and their members.
-
- Any good Ideas ????
-
- Would appreciate if you copied your reply to
- my e-mail address: ca@sesam.dnv.no
-
-
- Thanks,
- Carsten Arnholm
-
-
-
-
-
-